﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Asteroids.Game
{
    public class Nuke : Missile
    {
        public Nuke(Coordinate loc, double direction) : base(loc, direction)
        {
            Brush = Brushes.Red;
        }

        private const double ExplosionRadius = 150;

        protected override void OnDeath()
        {
            Game.Instance.ApplyExplosion(Location, ExplosionRadius);
            base.OnDeath();
        }

        public static Explosion CreateExplosion(Coordinate location, double radius)
        {
            return new Explosion(location, radius);
        }
    }

    public class Explosion : EntityBase
    {
        public Explosion(Coordinate location, double radius)
        {
            Location = location;
            Radius = radius;
        }

        public override Canvas Render(RenderEventArgs e)
        {
            var data = new Canvas();

            var ellipse = new Ellipse()
            {
                Width = Radius * 2,
                Height = Radius * 2,
                Fill = Brushes.OrangeRed.CloneCurrentValue(),
                Margin = new Thickness(Location.X - Radius, Location.Y - Radius, 0, 0),
            };
            ellipse.Fill.Opacity = 0.1;

            data.Children.Add(ellipse);

            return data;
        }
    }
}